﻿using RStudio.UIFramwork.Editor.Utils;
using RStudio.UIFramwork.Utils;
using UnityEditor;

namespace RStudio.UIFramwork.Editor
{
    /// <summary>
    /// 
    /// </summary>
    [CanEditMultipleObjects]
    [CustomEditor(typeof(UIWidget), true)]
    internal class EditUIWidget : UnityEditor.Editor
    {
        private UIWidget m_UIWidget;

        public void OnEnable()
        {
            m_UIWidget = target as UIWidget;
        }

        public override void OnInspectorGUI()
        {
            Version01();
        }


        public void Version01()
        {
            bool isGet = UIAssetUtil.IsUIDetailAttached(m_UIWidget.GetType(), out UIDetailAttribute output);
            string description = isGet ? output.Description : "缺失";
            string assetLink = isGet ? output.AssetLink : "缺失";
            EditorGUILayout.LabelField($"页面描述：{description}", EditorStyles.boldLabel);
            EditorGUILayout.LabelField($"资产路径：{assetLink}", EditorStyles.boldLabel);


            EditorGUILayout.Space();

            EditorGUILayout.LabelField("功能区", EditorStyles.boldLabel);
            {
                EditorGUILayout.BeginHorizontal("box");
                {
                    EditUIComponentUtil.UnitButton("唯一实例", ref m_UIWidget.UseAsSingle, m_UIWidget);
                }
                EditorGUILayout.EndHorizontal();
            }


            EditorGUILayout.LabelField("页面样式", EditorStyles.boldLabel);
            {
                EditorGUILayout.BeginHorizontal("box");
                {
                    EditUIComponentUtil.UnitButton("四周型", ref m_UIWidget.UseQuardRato, m_UIWidget);
                    EditUIComponentUtil.UnitButton("居中型", ref m_UIWidget.UseCentral, m_UIWidget);
                }
                EditorGUILayout.EndHorizontal();
            }


            base.OnInspectorGUI();
        }


    }
}
